<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\modules\Admin\models\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '学生列表';
$this->params['breadcrumbs'][] = $this->title;
?>
<style type="text/css">
    .cs1{margin:5px;}
</style>
<div class="user-index panel panel-body">

    <!-- <h1></?= Html::encode($this->title) ?></h1> -->

    <p>
        <?= Html::a('创建学生', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'layout'  =>  "{items}\n{pager}",
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            //'id',
            'schoolid',
            'name',
            'pinyin',
            'age',
            'password',
            [
                'attribute'=>'sex', 
                'filter' =>  Yii::$app->params['sex'],
                'format'=>'raw',
                'value' => function($model){
                        return isset(Yii::$app->params['sex'][$model->sex]) ? Yii::$app->params['sex'][$model->sex] : '';
                    }
            ],
            'classname',
            //'sign',
            'create_time',
            //'updated_at',

            [
                'label' => '禁言',
                'format'=> 'raw',
                'value' => function($model){

                    $url1  = sprintf("/admin/user/stop?id=%d&stop=1", $model->id);
                    $url2  = sprintf("/admin/user/stop?id=%d&stop=0", $model->id);

                    if($model->stop == 0){
                        $str = Html::a('禁言',$url1,['title' => '禁言','class'=>'btn btn-warning btn-xs cs1']);
                    }else{
                        $str = Html::a('取消禁言',$url2,['title' => '取消禁言','class'=>'btn btn-default btn-xs cs1']);
                    }
                    return $str;
                }
            ],

            [
                'label'=>'操作',
                'format'=>'raw',
                'value' => function($model){
                    $url1  = sprintf("/admin/user/view?id=%d", $model->id);
                    $url2  = sprintf("/admin/user/update?id=%d", $model->id);

                    $str = Html::a('查看',$url1,['title' => '查看','class'=>'btn btn-primary btn-xs cs1']);

                    $str .= Html::a('更新',$url2,['title' => '更新','class'=>'btn btn-success btn-xs cs1']);

                    $str .= Html::a('删除', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger btn-xs cs1','data' => [
                                'confirm' => Yii::t('app', '你确定要删除吗?'),
                                'method' => 'post',
                            ],]);
                
                    return $str;
                }
            ],
        
        ],
    ]); ?>


</div>
